*0b assembled matlab solutions
	forval f = 1/$K2 {
	cap {
	insheet using x_rhos`f'.csv,comma clear
		drop if v1==0
		rename v1 fup12
		rename v2 year
		rename v3 fid2yr
		rename v4 svshare

		rename v5 omega1_a
		rename v6 omega1_a_ft
		rename v7 rho1_a
		rename v8 fval1_a
		rename v9 exit1_a

		rename v10 omega1_b
		rename v11 omega1_b_ft
		rename v12 rho1_b
		rename v13 fval1_b
		rename v14 exit1_b

		rename v15 omega1_c
		rename v16 omega1_c_ft
		rename v17 rho1_c
		rename v18 fval1_c
		rename v19 exit1_c

		rename v20 omega1_d
		rename v21 omega1_d_ft
		rename v22 rho1_d 
		rename v23 fval1_d
		rename v24 exit1_d
		
		destring rho*, replace force

	** Choose the RHO from the starting value that minimizes objective function **
	forval j = 1/1 {
		egen min`j' = rmin(fval`j'_*)
		g i`j' = ""
		foreach v in a b c d {
			replace i`j' = "`v'" if fval`j'_`v' == min`j'
			}
		g rho`j'   = .
		g omega`j' = .
		g exit`j'  = .
		foreach v in a b c d {
			replace rho`j'   = rho`j'_`v' 		if i`j' == "`v'"
			replace omega`j' = omega`j'_`v'_ft 	if i`j' == "`v'"
			replace exit`j'  = exit`j'_`v' 		if i`j' == "`v'"
			}
		}
		rename rho1 rho_x
		rename omega1 omega_x
		rename omega1_a omega_fjt_x
		rename min1 min_x
		rename exit1 exit_x

		order fup12 year fid2yr svshare *_x
		keep  fup12 year fid2yr svshare *_x
		save ${worklocal}/rhos/tmp_rhos_`f',replace
	}
		}
		
	*combine files
*	!dir ${worklocal}/rhos/tmp_rhos*.dta >list1.txt
	cd ${worklocal}/rhos
	!dir tmp_rhos*.dta /a-d /b >list1.txt
	
	file open myfile using list1.txt, read
	file read myfile line
	use `line',clear
	saveold ${worklocal}/rhos,replace
	
	file read myfile line
	while r(eof)==0 {
		append using `line'
		file read myfile line
	}
	file close myfile
	save rhos,replace

	use rhos,clear
	sort fup12 year
		local llist = "x"
		foreach j of local llist {
			g converge_`j' = exit_`j'==1|exit_`j'==3
			}
	drop *fjt*
	keep fid fup12 year *_x
	compress
	sort fup12 year
saveold ${worklocal}/rhos,replace

